package Offer;

import java.util.Stack;

public class T9_Queue {
}

class CQueue {
    Stack<Integer> stack_input; //输入栈
    Stack<Integer> stack_output;//输出栈

    public CQueue() {
        stack_input = new Stack<>(); //完成入队的栈
        stack_output = new Stack<>();//完成出队的栈
    }

    public void appendTail(int value) {
        stack_input.push(value);
    }

    public int deleteHead() {
        if (stack_output.isEmpty()) {
            if (stack_input.isEmpty()) {
                return -1; //输入 输出栈都为空，返回-1
            }

            while (!stack_input.isEmpty()) { //将输入栈的元素弹出并压入到输出栈中，这样输出栈从栈顶到栈底的顺序就是队列从队首到队尾的顺序
                Integer top = stack_input.pop();
                stack_output.push(top);
            }
        }
        return stack_output.pop();
    }
}